/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ListPanel.java
 *
 * Created on Apr 9, 2009, 7:31:31 AM
 */

package ui;

import java.awt.GridLayout;
import java.util.ArrayList;

import documentSearching.Document;

/**
 * <b>ListPanel</b>
 *
 * <p>This class represents the window for viewing the search results of a query
 * in a list.</p>
 */
public class ListPanel extends javax.swing.JPanel implements ResultsDisplay
{

    /** Creates new form ListPanel */
    public ListPanel()
    {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        setBackground(new java.awt.Color(255, 255, 255));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 380, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents

    /**
     * Adds a search item that is to be displayed in the visual format.
     * @param doc - <code>Document</code> reference to displayed
     */
	@Override
	public void addDocument(Document doc) 
	{
		SearchResult result = new SearchResult(doc);
		
		this.add(result);
		
		this.validate();
	}
	
	/**
	 * Add a list of documents for user display
	 * @param docs - <code>ArrayList&ltDocument&gt</code> which are
	 * converted to <code>SearchResult</code> objects and displayed in a 
	 * list
	 */
	public void addDocuments(ArrayList<Document> docs)
	{
		GridLayout gl = new GridLayout(docs.size(), 1);
		
		this.setLayout(gl);
		
		for (Document d : docs)
		{
			addDocument(d);
		}
	}

	/**
	 * Removes all search results from view
	 */
	@Override
	public void clear() 
	{
		this.removeAll();
		this.revalidate();
	}
	
    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables

}
